package jssia.database.mysql.columns;

import java.util.HashSet;
import java.util.Set;

public class EnumBackedColumn <T extends Enum<T>> extends Column {

    /**
     * The class of the <code>enum</code> that defines all valid members
     * of this column.
     */
    final Class<T> enumType;

    /**
     * Constructs a <code>Column</code> that enforces that the members of the column
     * correspond to the values of the <code>enum</code> of type <code>clas</code>.
     *
     * @param clas the class of the <code>enum</code> that defines all valid members
     * of the column.
     */
    public EnumBackedColumn(Class<T> clas) {
        this.enumType = clas;
    }

    public Set<String> getValues() {
        final Set<String> values = new HashSet<String>();
        for (T t : enumType.getEnumConstants()) {
            values.add(t.toString());
        }
        return values;
    }
}
